var FY0 = "┏━━━━━━━━━━━┓";
var FY1 = "┃       - 枫叶 -       ┃";
var FY2 = "┃ 脚本仿制  　定制脚本 ┃";
var FY3 = "┃ 技术支持 　 游戏顾问 ┃";
var FY4 = "┃ ＷＺ添加　  地图制作 ┃";
var FY5 = "┃ 加盾防御　  售登陆器 ┃";
var FY6 = "┣━━━━━━━━━━━┫";
var FY7 = "┃ 唯一QQ:1848350048    ┃";
var FY8 = "┗━━━━━━━━━━━┛";
var 红色箭头 = "#fUI/UIWindow/Quest/icon6/7#";
var 蓝色箭头 = "#fUI/UIWindow/Quest/icon2/7#";
var 正方箭头 = "#fUI/Basic/BtHide3/mouseOver/0#";
var status = 0;

//普通奖池
var itemList1 = [
	//物品id，几率，数字越大概率越大，数量

[3010402, 1, 1, 0],
[3010403, 1, 1, 0],
[3010404, 1, 1, 0],
[3010405, 1, 1, 0],
[3010406, 1, 1, 0],
[3010421, 1, 1, 0],
[3010423, 1, 1, 0],
[3010431, 1, 1, 0],
[3010432, 1, 1, 0],
[3010433, 1, 1, 0],
[3010434, 1, 1, 0],
[3010435, 1, 1, 0],
[3010436, 1, 1, 0],
[3010437, 1, 1, 0],
[3010438, 1, 1, 0],
[3010439, 1, 1, 0],
[3010440, 1, 1, 0],
[3010441, 1, 1, 0],
[3010442, 1, 1, 0],
[3010443, 1, 1, 0],
[3010444, 1, 1, 0],
[3010445, 1, 1, 0],
[3010446, 1, 1, 0],
[3010447, 1, 1, 0],
[3010450, 1, 1, 0],
[3010451, 1, 1, 0],
[3010452, 1, 1, 0],
[3010455, 1, 1, 0],
[3010457, 1, 1, 0],
[3010458, 1, 1, 0],
[3010459, 1, 1, 0],
[3010500, 1, 1, 0],
[3010501, 1, 1, 0],
[3010502, 1, 1, 0],
[3010503, 1, 1, 0],
[3010504, 1, 1, 0],
[3010505, 1, 1, 0],
[3010506, 1, 1, 0],
[3010512, 1, 1, 0],
[3010513, 1, 1, 0],
[3010514, 1, 1, 0],
[3010515, 1, 1, 0],
[3010516, 1, 1, 0],
[3010517, 1, 1, 0],
[3010518, 1, 1, 0],
[3010519, 1, 1, 0],
[3010520, 1, 1, 0],
[3010521, 1, 1, 0],
[3010522, 1, 1, 0],
[3010523, 1, 1, 0],
[3010524, 1, 1, 0],
[3010525, 1, 1, 0],
[3010526, 1, 1, 0],
[3010530, 1, 1, 0],
[3010531, 1, 1, 0],
[3010600, 1, 1, 0],
[3010601, 1, 1, 0],
[3010611, 1, 1, 0],
[3010612, 1, 1, 0],
[3010613, 1, 1, 0],
[3010622, 1, 1, 0],
[3010623, 1, 1, 0],
[3010624, 1, 1, 0],
[3010552, 1, 1, 0],
[3010553, 1, 1, 0],
[3010554, 1, 1, 1]

];

var useNx = 10000000;
var sel0 = -1;
function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (status == 0 && mode == 0) {
        cm.dispose();
        return;
    }
    if (mode == 1) {
        status++;
    } else {
        status--;
    }

    if (status == 0) {
    	var txt = "#d开启宝箱后你将随机获得以下奖励#n#k\r\n";
		
    	txt += "#d#L1##r"+红色箭头+蓝色箭头+" 点击开箱#l\r\n\r\n\r\n\r\n";
		txt += "#b"+正方箭头+" 奖品展示： \r\n";
		
		var txt2 = "";
		for (var i = 0; i < itemList1.length;  i++){
			txt2 += "#i"+itemList1[i][0]+":#";
		}
    	cm.sendSimple(txt + txt2);
    } else if (status == 1) {
		var jobid=cm.getPlayer().getJob();
		//if (jobid==112||jobid==122||jobid==132||jobid==212||jobid==222||jobid==232||jobid==312||jobid==322||jobid==412||jobid==422||jobid==512||jobid==522||jobid==2112||jobid==1112||jobid==1111||jobid==1211||jobid==1311||jobid==1411||jobid==1511){
		sel0 = selection;
		cm.sendGetNumber(""+正方箭头+"#d 你需要开多少个?\r\n"
		+"#d每次消耗一个宝箱和一把联盟钥匙",
		1, 1, 99999
		);
		//}else {
         //   cm.sendOk("您好，金币抽奖需要您先完成所有转职后才可以进行抽奖哦！");
         //   cm.dispose();
         //   }
	} else if(status == 2) {
		if (!cm.checkNumSpace(0, selection)) {
			cm.sendOk("背包空间不足"+selection+"格");
			cm.dispose();
			return;
		}
    	switch (sel0) {
			case 1:
                if (!cm.haveItem(2028074,selection) || !cm.haveItem(4000435,selection)) 
				{
					cm.sendOk("你没有#r "+(1*selection)+" 个宝箱或是联盟钥匙#k，无法开启宝箱");
					cm.dispose();
					return;
				} 
				else
				{
					cm.gainItem(2028074,-selection);
					cm.gainItem(4000435,-selection);
					cm.setBossLog("椅子宝箱开箱次数",1,selection);
				}
				break;
			case 2:
                if (cm.getMeso() < (useNx*selection)) {
					cm.sendOk("金币不足"+(useNx*selection)+"，无法抽奖");
					cm.dispose();
					return;
				} else {
					cm.gainMeso(-useNx*selection);
				}
				break;
			default:
				cm.sendOk("脚本出错，请联系管理员");
				cm.dispose();
				return;
        }
		var txt = "恭喜你获得道具：\r\n";
		for (var i = 0; i < selection; i++) {
			var item;
			var ran = Math.floor(Math.random() * 100);
			var ran1 = null;
			ran1 = finalGift(itemList1);
			if(cm.getBossRankCount("屏蔽"+ran1[0]) > 0){
				cm.gainGachaponItem2(4001126, 1, "枫叶", ran1[3]);
			}
			else
			{
				var sjpp = Math.floor(Math.random()*20)+10;
				var suiji1 = Math.floor(Math.random()*10)+1;
				var suiji2 = Math.floor(Math.random()*10)+1;
				var suiji3 = Math.floor(Math.random()*10)+1;
				var suiji4 = Math.floor(Math.random()*10)+1;
				var suijigg = Math.floor(Math.random()*20)+sjpp+(100-ran1[2]);
				var suijigg2 = Math.floor(Math.random()*20)+sjpp+(100-ran1[2]);
				var suiji5 = Math.floor(Math.random()*200);
				cm.gainGachaponItem2(ran1[0], ran1[2], "椅子宝箱", 1);
			}
			cm.gainItem(4000313, 1);
			//cm.gainItem(ran1[0] ,ran1[2])
			//cm.worldMessage("『抽奖捷报』：恭喜玩家."+ cm.getChar().getName() +"  获得["+ Packages.server.MapleItemInformationProvider.getInstance().getName(ran1[0]) +"]让我们热烈的祝福他/她吧！");
			txt += "#v" + ran1[0] + "#\r\n";
			//var result = cm.setBossRankCount("随机奖池抽奖");
			/*
			var ran2 = null;
			if (result%10 == 0) {//十连抽保底
				ran2 = finalGift(itemList1);
				cm.gainItem(ran2[0] ,ran2[2])
				txt += "额外道具：#v" + ran2[0] + "#\r\n";
			}
			*/
		}
		cm.dispose();
		return;
    }
}

function finalGift(lists) {
	var maxChance = 0;
	for (var i in lists) {
		if (lists[i][1] > maxChance) {
			maxChance = lists[i][1];
		}
	}
	var chance = Math.floor(Math.random() * maxChance);
	var finalitem = Array();
	for (var i = 0; i < lists.length; i++) {
		if (lists[i][1] >= chance) {
			finalitem.push(lists[i]);
		}
	}
	var ran1 = Math.floor(Math.random() * finalitem.length);
	return finalitem[ran1];
}